#ifndef TRAVERSETHREAD_H
#define TRAVERSETHREAD_H

#include <QRunnable>
#include "mgraph.h"
#include "matrixwidget.h"
#include "mpainter.h"
#include <QThread>
class TraverseThread : public QRunnable
{
public:
    TraverseThread(MatrixWidget *w,MPainter *mp,MGraph<string> *mg):w(w),mp(mp),mg(mg){}

    void SwitchDFS(){
        style=0;
    }
    void SWitchBFS(){
        style=1;
    }
    void run(){
        switch (style) {

        case 0:
            //深度优先
            mg->DFSTraverse([&](int index,string str)->void{
                mp->currentnode=index;

                mp->update();
                QThread::sleep(1);
             });
            break;
        case 1:
            //广度优先
            mg->BFSTraverse([&](int index,string str)->void{
                mp->currentnode=index;
                //qDebug()<<QString::fromStdString(str);
                mp->update();
                QThread::sleep(1);
            });
            break;
        }
    }
    int style=0;
    MatrixWidget *w;
    MPainter *mp;
    MGraph<string> *mg;
};

#endif // TRAVERSETHREAD_H
